package 斐波那契数列;

public class Fibonacci
{
    public long get(int n)
    {
        int[] result = {0, 1};
        if (n < 2)
            return result[n];
        long fibNMinusone = 1;
        long fibNMinustwo = 0;
        long fibN = 1;
        for (int i = 2; i <= n; i++)
        {
            fibN = fibNMinusone + fibNMinustwo;
            fibNMinustwo = fibNMinusone;
            fibNMinusone = fibN;
        }
        return fibN;
    }

    public static long fib(int x)
    {
        if (x == 1 || x == 2)
        {
            return 1;
        } else
            return fib(x - 1) + fib(x - 2);
    }

    public static void main(String[] args)
    {
        System.out.println(fib(4));

        Fibonacci fibonacci = new Fibonacci();
        System.out.println(fibonacci.get(4));
    }
}
